{% extends '../index.html' %}
{% block content %}

<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">分类列表</div></div>
                <div class="widget-body  am-fr">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">

                            </div>
                        </div>
                    </div>
                    <form action="{% url 'myadmin_goodslist' %}">
                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                            <div class="am-form-group tpl-table-list-select">
                                <select name="types" data-am-selected="{btnSize: 'sm'}">
                                    <option {% if request.GET.types == 'all' %}selected {% endif %} value="all">所有类别</option>
                                    <option {% if request.GET.types == 'cid' %}selected {% endif %}value="cid">ID</option>
                                    <option {% if request.GET.types == 'cname' %}selected {% endif %} value="cname">类名</option>
                                </select>
                            </div>
                        </div>
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                            <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                <input name="search" type="text" class="am-form-field " value="{{request.GET.search}}">
                                <span class="am-input-group-btn">
                                    <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" ></button>
                                </span>
                            </div>
                        </div>
                    </form>
                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " >
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>商品类名</th>
                                    <th>upid</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for i in goodlist %}
                                <tr class="gradeX">
                                    <td>{{i.id}}</td>
                                    <td class="inp" id={{i.id}}>
                                        {% for j in i.num %}
                                        <span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
                                        {% endfor %}
                                        {% if i.upid != 0 %}
                                        |&nbsp;
                                        {% endif %}
                                        <span class="cinp">{{i.cname}}</span>
                                    </td>
                                    <td class="{{i.upid}}">{{i.level}}</td>
                                    <td>{{i.addtime}}</td>
                                    <td>
                                        <div class="tpl-table-black-operation">
                                            <a href="javaScript:void(0)" pid="{{i.id}}"class="tpl-table-black-operation-del del">
                                                <i class="am-icon-trash"></i>删除</a>
                                        </div>
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>

                            <script type="text/javascript">
                                $(".del").click(function(){
                                    var pid = $(this).attr("pid")
                                    var el = $(this).parents('tr')
                                    $.get("{% url 'myadmin_delgoods' %}",{pid:pid},function(data){
                                        if (data["msg"] == 0) {
                                            alert("删除失败,该类别有子类")
                                        }else if (data["msg"] == 1) {
                                            
                                            el.remove()
                                        }
                                    },"json")
                                })
                                $(".inp").dblclick(function(){
                                    var id = $(this).attr("id")
                                    var upid="."+id
                                    var upname=$(upid)
                                    var oldname=$(this).find("span").last().text()
                                    var sp = $(this).find("span").last()
                                    var Inp=$('<input type="text" name="newname">')
                                    $(this).find("span").last().html(Inp)
                                    $(this).find("input").css("color","black")
                                    // 光标获取
                                    $(this).find("input").val("").focus().val(oldname);
                                    Inp.blur(function(){
                                        var newname = $(this).val()
                                        if (newname == oldname) {
                                            $(this).parent().html(oldname)
                                        }else{
                                            $.get("{% url 'myadmin_rename' %}",{id:id,msg:newname},function(data){
                                                    if (data["data"] == 1) {
                                                        sp.html(newname)
                                                        upname.html(newname)                                           
                                                    }else if (data["data"] == 0) {
                                                        sp.html(oldname)
                                                    }


                                            },'json')
                                        } 
                                    })
                                    
                                })

                            </script>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                                <li ><a href="{% url 'myadmin_goodslist' %}?p=1&types={{request.GET.types}}&search={{request.GET.search}}">首页</a></li>                                
                                <li {% if page == 1 %}class="am-disabled"{% endif %} >
                                    <a href="{% url 'myadmin_goodslist' %}?p={{page|add:-1}}&types={{request.GET.types}}&search={{request.GET.search}}">«</a></li>
                                {% for i in prange %}
                                <li {% if page == i %}class="am-active"{% endif %}>
                                    <a href="{% url 'myadmin_goodslist' %}?p={{i}}&types={{request.GET.types}}&search={{request.GET.search}}">{{i}}</a>
                                </li>
                                {% endfor %}
                                <li {% if page == sumpage %}class="am-disabled"{% endif %}>
                                    <a href="{% url 'myadmin_goodslist' %}?p={{page|add:1}}&types={{request.GET.types}}&search={{request.GET.search}}">»</a></li>
                                <li ><a href="{% url 'myadmin_goodslist' %}?p={{sumpage}}&types={{request.GET.types}}&search={{request.GET.search}}">尾页</a></li>                                     
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}